@extends('layout.member')

@section('body')
  <div class="panel active">
    <div class="panel-head">
      <h4>添加App物料</h4>
    </div>
    <div class="panel-body">
      <form class="layui-form layui-form-pane">
        @include('member.materiel.app.body')
      </form>
    </div>
  </div>
@endsection
@section('js')
  <script type="text/javascript">
      layui.use(['form'], function () {
          var form = layui.form;
          //自定义验证规则
          form.verify({
              visits_min: function (value) {
                  var visits_max = $('input[name=visits_max]').val();
                  if (value < 1) {
                      return '访问最小值必须大于1';
                  } else if (parseInt(value) > parseInt(visits_max)) {
                      return '访问最小值不能大于最大值';
                  }
              },
              visits_max: function (value) {
                  var visits_min = $('input[name=visits_min]').val();
                  if (value < 1) {
                      return '访问最大值必须大于1';
                  } else if (parseInt(value) < parseInt(visits_min)) {
                      return '访问最大值不能小于最小值';
                  }
              }
          });
          //监听提交
          form.on('submit(submitMaterielApp)', function (data) {
              var param = data.field;
              $.post("{{route('materielApp.update',$materielApp->id)}}",
                  {
                      _token: '{{csrf_token()}}',
                      _method: 'PUT',
                      param: param
                  },
                  function (data) {
                      if (data.status == 200) {
                          layer.msg(data.msg);
                          setTimeout(function () {
                              window.location.href = data.data;
                          }, 1500);
                      } else {
                          layer.msg(data.msg);
                      }
                  });
              return false;
          });
      });
  </script>
@append